package com.lsf.dunlian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.lsf.dunlian.R;
import com.lsf.dunlian.activity.FollowUpActivity;
import com.lsf.dunlian.activity.MemberDetailActivity;
import com.lsf.dunlian.activity.MemberHanlerActivity;
import com.lsf.dunlian.entity.AllNoticeRecordData;
import com.lsf.dunlian.entity.MemberHandlerEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MemberHandlerRecyclerViewAdapter extends RecyclerView.Adapter<MemberHandlerRecyclerViewAdapter.ViewHolder> {
    private List<MemberHandlerEntity> mDataList;
    private Context context;
    private String data;

    public MemberHandlerRecyclerViewAdapter(List<MemberHandlerEntity> mDataList, Context context, String data) {
        this.mDataList = mDataList;
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public MemberHandlerRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.member_handler_item, parent, false);
        MemberHandlerRecyclerViewAdapter.ViewHolder holder = new MemberHandlerRecyclerViewAdapter.ViewHolder(view);
        return holder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        MemberHandlerEntity memberHandlerEntity = mDataList.get(position);
        holder.img.setBackgroundResource(memberHandlerEntity.img);
        holder.name.setText(memberHandlerEntity.name);

        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (memberHandlerEntity.type) {
                    case 1:
                        Intent intent = new Intent(context, MemberDetailActivity.class);
                        intent.putExtra("data", data);
                        context.startActivity(intent);
                        break;
                    case 2:
                        Intent intent2 = new Intent(context, FollowUpActivity.class);
                        context.startActivity(intent2);
                        break;
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img)
        ImageView img;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.layout)
        LinearLayout layout;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
